package cn.itcast.mytest;

import cn.itcast.n2.util.Sleeper;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

@Slf4j(topic = "c.Test04")
public class Test04 {

    public static void main(String[] args) {
        test1();
    }

    public static void test1(){
        Object A = new Object();
        Object B = new Object();

        Thread t1 = new Thread(() -> {
            synchronized (A){
                log.debug("lock A");
                Sleeper.sleep(1);
                synchronized (B){
                    log.debug("lock B");
                    log.debug("操作");
                }
            }
        }, "t1");

        Thread t2 = new Thread(() -> {
            synchronized (B){
                log.debug("lock B");
                Sleeper.sleep(1);
                synchronized (A){
                    log.debug("lock A");
                    log.debug("操作");
                }
            }
        }, "t2");

        t1.start();
        t2.start();
    }
}
